/*
 * @Author: your name
 * @Date: 2021-05-29 16:43:00
 * @LastEditTime: 2021-05-29 16:48:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/order/recharge/index.tsx
 */
/*
 * @Author: your name
 * @Date: 2021-05-29 16:43:21
 * @LastEditTime: 2021-05-29 16:44:24
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/order/consumption/index.tsx
 */
/*
 * @Author: your name
 * @Date: 2021-05-22 21:52:40
 * @LastEditTime: 2021-05-29 16:39:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /xiangpan-admin/src/pages/order/index.tsx
 */
import { IForm } from '@/components/form/interface';
import { Card, Table, TablePaginationConfig, Tabs } from 'antd';
import React from 'react';
import { IFormTypeEnum } from '@/components/form/formComponent';
import HeaderForm from '@/components/form';
import { useRequest } from '@/.umi/plugin-request/request';
import { get_admin_list, get_recharge_list } from '@/services/pages';
import initPagination from '@/use/initPagination';
import useObj from '@/use/useObj';
import { useEffect } from 'react';
import { formatDateTime } from '@/utils/utils';

interface IProps {}

const Recharge = (props: IProps) => {
  const [obj, setObj] = useObj({
    ...initPagination,
    visible: false,
    refresh: null,
    row: null,
    search: null,
  });

  const { data, error, loading } = useRequest(
    () =>
      get_recharge_list({
        page_size: obj.pagination.pageSize,
        page_num: obj.pagination.current,
        search: obj.search,
      }),
    {
      refreshDeps: [obj.pagination, obj.refresh, obj.search],
    },
  );

  useEffect(() => {
    setObj((obj) => {
      obj.pagination.total = data?.results[0]?.total || 0;
    });
  }, [data]);
  const columns: IForm[] = [
    {
      key: 'recharge_id',
      dataIndex: 'recharge_id',
      title: '订单单号',
    },
    {
      key: 'user_name',
      dataIndex: 'user_name',
      title: '会员名称',
    },
    {
      key: 'money',
      dataIndex: 'money',
      title: '充值金额(元)',
      render: (text) => {
        return <span>{text / 100}</span>;
      },
    },
    {
      key: 'store_name',
      dataIndex: 'store_name',
      title: '门店名称',
    },
    {
      key: 'create_time',
      dataIndex: 'create_time',
      title: '创建时间',
      render: (text) => {
        return formatDateTime(text);
      },
    },
  ];

  const List = [
    {
      key: 'search',
      type: IFormTypeEnum.Input,
      label: '会员名称',
    },
  ];
  return (
    <div>
      {' '}
      <HeaderForm
        list={List}
        style={{ marginBottom: 15 }}
        onSubmit={(form) => {
          setObj({ search: form.search });
        }}
      />
      <Table
        rowKey={(record) => record.admin_id}
        loading={loading}
        columns={columns}
        dataSource={data?.results}
        pagination={obj.pagination}
        onChange={(pagination: TablePaginationConfig): void => {
          const { current, pageSize } = pagination;
          setObj((obj: any) => {
            obj.pagination.current = current;
            obj.pagination.pageSize = pageSize;
            obj.onReFresh = Symbol();
          });
        }}
      />
    </div>
  );
};
export default Recharge;
